import { API } from '@/helpers/axios'
import { buildSearchParamsWithLocale } from '@/helpers/urlParamsHelper'
import { formatLocalDateString } from '@/yichat.web.share/helpers/DateHelper'

export const generateEventParams = () => ({
  initiatedAt: {
    timestamp: formatLocalDateString(new Date())
  },
  referer: window.referrerURL || ''
})

export default {
  create(name) {
    const search = buildSearchParamsWithLocale(window.location.search)
    return API.post(`/api/v1/widget/events${search}`, { name })
  }
}
